iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 20
1
自我挑戰組

Linux學習系列 第 20

Ubuntu Apache2檔案和資料夾

  • 分享至 

  • xImage
  •  

接著繼續:
https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04

Step 6 – Getting Familiar with Important Apache Files and Directories

Content:
/var/www/html
這個就是原本放HTML的資料夾,裡面有個index.html,就是沒更改前的網頁

Server Configuration:
/etc/apache2
The Apache configuration directory.
All of the Apache configuration files reside here

/etc/apache2/apache2.conf
The main Apache configuration file
This can be modified to make changes to the Apache global configuration
This file is responsible for loading many of the other files in the configuration directory
如圖,有個/etc/apache2的架構圖
https://ithelp.ithome.com.tw/upload/images/20181102/20111994wrBMxRwX1B.png

/etc/apache2/ports.conf
This file specifies the ports that Apache will listen on.
By default, Apache listens on port 80
Apache listens on port 443 when a module providing SSL capabilities is enabled
https://ithelp.ithome.com.tw/upload/images/20181102/20111994pcRDZsdvE1.png

/etc/apache2/sites-available/
The directory where per-site virtual hosts can be stored.
Apache will not use the configuration files found in this directory unless they are linked to the sites-enabled directory
Typically, all server block configuration is done in this directory, and then enabled by linking to the other directory with the a2ensite command.
Apache不會用別的html,除非/etc/apache2/sites-available/這個資料夾的conf檔有enable,也是可以在其他資料夾的conf檔enable,使用a2ensite指令

/etc/apache2/sites-enabled/
/etc/apache2/sites-available/是放每個html的設定檔
/etc/apache2/sites-enabled/是放允許的html的設定檔
像是目前就只允許tedtedtedtedted.com
所以就只會有tedtedtedtedted.com.conf

/etc/apache2/conf-available/, /etc/apache2/conf-enabled/
類似於sites-available and sites-enabled directories
就是其他的設定檔裡面的檔案有像是:security.conf、other-vhosts-access-log.conf

/etc/apache2/mods-available/, /etc/apache2/mods-enabled/
Files in ending in .load contain fragments to load specific modules
files ending in .conf contain the configuration for those modules

Server Logs
/var/log/apache2/access.log
By default, every request to your web server is recorded in this log file unless Apache is configured to do otherwise
當使用者瀏覽網頁時,網頁伺服器會知道一些使用者的資料,/var/log/apache2/access.log檔案有IP地址、時間、HTTP Status、作業系統名稱等等
HTTP Status:
https://www.puritys.me/docs-blog/article-45-Http-status-%E7%8B%80%E6%85%8B-404-304.html
這邊可以用pipe來練習,像是
因為IP地址在最左邊,所以使用cut -d ' ' -f 1可以印出IP地址
cat /var/log/apache2/access.log | cut -d ' ' -f 1 | less

印出IP地址後,sort按照IP地址排序,uniq –c把重複的去掉,然後顯示IP地址重複了幾次
cat /var/log/apache2/access.log | cut -d ' ' -f 1 | sort | uniq –c

接著可以是用tee把資料存到檔案ipaddress
cat /var/log/apache2/access.log | cut -d ' ' -f 1 | sort | uniq -c | tee ~/ipaddress

接著來看使用者的作業系統

cat /var/log/apache2/access.log | cut -d "(" -f 2 | cut -d ")" -f 1
會有408
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408
https://ithelp.ithome.com.tw/upload/images/20181102/20111994Ho0U1UuSdw.png
想辦法去除408
cat /var/log/apache2/access.log | cut -d "(" -f 2 | cut -d ")" -f 1 | grep -v 408 | sort | uniq –c
https://ithelp.ithome.com.tw/upload/images/20181102/20111994H6xUUr1qei.png
接著來練習 顯示時間和ip位址
awk:
https://blog.longwin.com.tw/2006/12/linux_cut_2006/
cat /var/log/apache2/access.log | cut -d '"' -f 1 | awk -F- -v 'OFS= is ' '{print $3,$1}'
https://ithelp.ithome.com.tw/upload/images/20181102/20111994T8Xpc3i1Id.png
接著來取得HTTP Status
https://askubuntu.com/questions/733265/what-is-get-http-1-1-200-19019
https://ithelp.ithome.com.tw/upload/images/20181102/20111994JOgT2JgpiI.png

/var/log/apache2/error.log
By default, all errors are recorded in this file


上一篇
Ubuntu apache2 html 、VirtualBox改成ssh連線
下一篇
Linux MySQL
系列文
Linux學習30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言